<template>
  <div class="dashboard-container">
    <!-- <div class="dashboard-text">姓名:{{ name }}</div>
    <div class="dashboard-text">账号:<span>{{ account }}</span></div> -->
    <div class="warning-box">
      <div class="warning-cycle cycle1">
        <div>车辆</div>
        <div @click="linkto(1)" style="text-decoration: underline;cursor: pointer;">里程预警{{ warningList['里程'].length }}条</div>
      </div>
      <div class="warning-cycle cycle2">
        <div>车辆</div>
        <div @click="linkto(2)" style="text-decoration: underline;cursor: pointer;">时间预警{{ warningList['时间'].length }}条</div>
      </div>
      <div class="warning-cycle cycle3">
        <div>人员证件</div>
        <div @click="linkto(3)" style="text-decoration: underline;cursor: pointer;">到期预警{{ warningList['证件'].length }}条</div>
      </div>
      <div class="warning-line line1"></div>
      <div class="warning-line line2"></div>
      <div class="warning-line line3"></div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { warningList } from '@/api/api'

export default {
  name: 'Dashboard',
  data() {
    return {
      warningList: {
        '时间': [],
        '证件': [],
        '里程': [],
      },
    }
  },
  created() {
    this.getWarningList()
  },
  computed: {
    ...mapGetters([
      'name',
      'account',
      'roles'
    ]),

  },
  methods: {
    async getWarningList() {
      const res = await warningList()
      if (res.code == 0) {
        this.warningList = res.data.list
      }
    },
    linkto(type) {
      switch(type) {
        case 1: if (this.warningList['里程'].length) {this.$router.push({name: 'details', params: {yjdl: '车辆', yjzl: '里程'}})};break;
        case 2: if (this.warningList['时间'].length) {this.$router.push({name: 'details', params: {yjdl: '车辆', yjzl: '时间'}})};break;
        case 3: if (this.warningList['证件'].length) {this.$router.push({name: 'details', params: {yjdl: '人员', yjzl: '证件'}})};break;
      }
    },
  },
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.dashboard {
  &-container {
    margin: 30px;
  }
  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}
.dashboard-container{
  width: 100%;
  height: 100%;
  margin: 0;
}
.warning-box{
  position: relative;
  width: 100%;
  height: calc(100vh - 50px);
  .warning-cycle{
    width: 17%;
    height: 12%;
    background-color: #F56C6C;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: absolute;
    &.cycle1{
      left: 24%;
      top: 20%;
    }
    &.cycle2{
      left: 59%;
      top: 20%;
    }
    &.cycle3{
      left: 41.5%;
      top: 45%;
    }
  }
  .warning-line{
    width: 20%;
    height: 2px;
    background-color: #F56C6C;
    position: absolute;
    &.line1{
      left: 40%;
      top: 26%;
    }
    &.line2{
      left: 28%;
      top: 39%;
      transform: rotateZ(45deg);
    }
    &.line3{
      left: 52%;
      top: 39%;
      transform: rotateZ(-45deg);
    }
  }
}
</style>
